package com.vic.dead_letter_queue.max_length;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.vic.dead_letter_queue.Consts;
import com.vic.utils.RabbitmqUtils;

import java.nio.charset.StandardCharsets;

/**
 * 生产者
 */
public class Producer {

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitmqUtils.getChannel();

        // 声明一个 direct 类型的交换机
        channel.exchangeDeclare(Consts.NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);

        // 待发送的消息
        String message = "putrid";
        for (int i = 1; i <= 5; i++) {
            channel.basicPublish(Consts.NORMAL_EXCHANGE, Consts.NORMAL_ROUTING_KEY, MessageProperties.PERSISTENT_TEXT_PLAIN, (message + i).getBytes(StandardCharsets.UTF_8));
        }

        System.out.println("消息发送完毕");
    }

}
